<?php

namespace App\Admin\Controllers;

use App\Models\Score;
use App\Models\Meet;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Encore\Admin\Facades\Admin;

class ScoresController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('Index')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('Edit')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('Create')
            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Score);
        $grid->actions(function ($actions) {
            $actions->disableView();
        });
        $grid->filter(function($filter){
            $filter->disableIdFilter();
            $filter->equal('meet_id', '分享记录');
        });
        Admin::script('
        $("#filter-box").hide();
        ');
        $grid->id('Id');
        $grid->column('meet.title','分享题目');
        $grid->question_one('语言组织和表达能力');
        $grid->question_two('分享课件准备程度');
        $grid->question_three('实用性');
        $grid->question_four('深度与难度');
        $grid->question_five('新知识和新理念获取');
        $grid->sum('总得分');
        $grid->advice_member('对分享者的建议');
        $grid->advice_meet('对分享会的建议');
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Score::findOrFail($id));

        $show->id('Id');
        $show->meet_id('Meet id');
        $show->question_one('Question one');
        $show->question_two('Question two');
        $show->question_three('Question three');
        $show->question_four('Question four');
        $show->question_five('Question five');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Score);

        $form->select('meet_id', '分享标题')->options(Meet::all()->pluck('title','id'));;
        $form->number('question_one', '语言组织和表达能力');
        $form->number('question_two', '分享课件准备程度');
        $form->number('question_three', '实用性');
        $form->number('question_four', '深度与难度');
        $form->number('question_five', '新知识和新理念获取');
        $form->text('advice_member','对分享者的建议');
        $form->text('advice_meet','对分享会的建议');

        return $form;
    }
}
